package com.fl;

import java.nio.charset.Charset;
import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;


import com.fl.conf.ApplicationStartup;


@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan(value = {"com.fl.controller.**","com.fl.service.**","com.fl.util.**","com.fl.task.**","com.fl.properties.**","com.fl.conf.**"})
@MapperScan(basePackages = "com.fl.mapper")
public class Application extends WebMvcConfigurerAdapter {

    public static void main(String[] args) {
    	
    	SpringApplication springApplication = new SpringApplication(com.fl.Application.class);
    	springApplication.addListeners(new ApplicationStartup());
        springApplication.run( args);
        
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

    	registry.addResourceHandler("/MP_verify_ygsQPOMsql0X6oiL.txt")
    		.addResourceLocations("classpath:/static/txt/MP_verify_ygsQPOMsql0X6oiL.txt");
    	
    	registry.addResourceHandler("/MP_verify_c8E501fdwuPiqO3G.txt")
		.addResourceLocations("classpath:/static/txt/MP_verify_c8E501fdwuPiqO3G.txt");
    	super.addResourceHandlers(registry);
    	
    	registry.addResourceHandler("/MP_verify_fnYlnTvVqafEhuUV.txt")
		.addResourceLocations("classpath:/static/txt/MP_verify_fnYlnTvVqafEhuUV.txt");
    	super.addResourceHandlers(registry);
    	
    	
    	registry.addResourceHandler("/MP_verify_R5yva3QxFT2Mjcdo.txt")
		.addResourceLocations("classpath:/static/txt/MP_verify_R5yva3QxFT2Mjcdo.txt");
    	super.addResourceHandlers(registry);
    	
    	
    	
    }
    
    

    
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
      registry.addViewController("/").setViewName("home");
      registry.addViewController("/error").setViewName("error");
      registry.addViewController("/profile").setViewName("profile");
    }

    
    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer() {
      return container -> container.addErrorPages(new org.springframework.boot.web.servlet.ErrorPage(HttpStatus.NOT_FOUND, "/error"), new org.springframework.boot.web.servlet.ErrorPage(HttpStatus.FORBIDDEN, "/error"));
    }   

    @Override  
    public void configureMessageConverters( List<HttpMessageConverter<?>> converters) {  

    		super.configureMessageConverters(converters);  
            org.springframework.http.converter.StringHttpMessageConverter StringConverter=new org.springframework.http.converter.StringHttpMessageConverter(Charset.forName("UTF-8"));
            converters.add(StringConverter);
            org.springframework.http.converter.json.MappingJackson2HttpMessageConverter messageConverter=new org.springframework.http.converter.json.MappingJackson2HttpMessageConverter();
            converters.add(messageConverter);
            		
    }   
}
